package com.sunwayhorizo.health.hl7.rim;

import com.sunwayhorizo.health.common.*;
import com.sunwayhorizo.health.hl7.common.*;
import com.sunwayhorizo.health.hl7.datatypes.*;
import com.sunwayhorizo.health.hl7.factories.*;
import com.sunwayhorizo.health.hl7.persistent.*;
import java.io.*;
import java.sql.*;
import javax.persistence.*;
import org.jboss.seam.annotations.*;
import static com.sunwayhorizo.health.hl7.vocabulary.EntityCdSetCode.*;

@Name("Device")
@Entity
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorValue("DEV")
public class Device extends ManufacturedMaterial implements Serializable
{

    /**
     * 
     */
    private static final long serialVersionUID = 1L;


    /*
     * public CE AlertLevelCode; public TS LastCalibrationTime; public CE
     * LocalRemoteControlStateCode; public SC ManufacturerModelName; public SC
     * SoftwareName;
     */
    public Device() throws Hl7Exception
    {
    }


    public Device(ReferenceModifier referencemodifier)
    {
        super(referencemodifier);
    }


    public void setAlertLevelCode(CE ce)
    {
        if (null != ce && ce.codeSystemEnName() != null && ce.codeName() != null)
        {
            setRimCoreEntyCdSets(ce, ALERTLEVELCODE);
        }
        else
        {
            this.setDvAlertLevelCodeEtsId(ce.code().toString());
        }
    }


    public CE getAlertLevelCode() throws Hl7Exception
    {
        if (this.getDvAlertLevelCodeEtsId().equals(ALERTLEVELCODE.toString()))
        {
            for (RimCoreEntyCdSets entityCdSets : this.getEntyCdSetsList())
            {
                if (this.getDvAlertLevelCodeEtsId().equals(entityCdSets.getAttributeTypeCode()))
                {
                    return DataTypeUtil.getCE(entityCdSets);
                }
            }
        }
        else
            return DataTypeUtil.getCE(this.getDvAlertLevelCodeEtsId());
        return null;
    }


    public void setLastCalibrationTime(TS LastCalibrationTime)
    {
        this.setDvLastCalibrationDateTs(new Timestamp(LastCalibrationTime.toDate().getTime()));
        this.setDvLastCalibrationDateTxt(LastCalibrationTime.literal().toString());
    }


    public TS getLastCalibrationTime() throws Hl7Exception
    {
        return DataTypeUtil.getTS(this.getDvLastCalibrationDateTs());
    }


    public void setLocalRemoteControlStateCode(CE ce)
    {
        if (null != ce && ce.codeSystemEnName() != null && ce.codeName() != null)
        {
            setRimCoreEntyCdSets(ce, LOCALREMOTECONTROLSTATECODE);
        }
        else
        {
            this.setDvLocRemCtrlStateEtsId(ce.code().toString());
        }
    }


    public CE getLocalRemoteControlStateCode() throws Hl7Exception
    {
        if (this.getDvLocRemCtrlStateEtsId().equals(LOCALREMOTECONTROLSTATECODE.toString()))
        {
            for (RimCoreEntyCdSets entityCdSets : this.getEntyCdSetsList())
            {
                if (this.getDvLocRemCtrlStateEtsId().equals(entityCdSets.getAttributeTypeCode()))
                {
                    return DataTypeUtil.getCE(entityCdSets);
                }
            }
        }
        else
            return DataTypeUtil.getCE(this.getDvLocRemCtrlStateEtsId());
        return null;
    }


    public void setManufacturerModelName(SC ManufacturerModelName)
    {
        this.setDvMnfctrrModelName(ManufacturerModelName.toString());
        this.setDvMnfctrrModelCodeEtsId(ManufacturerModelName.code().toString());
    }


    public SC getManufacturerModelName() throws Hl7Exception
    {
        return DataTypeUtil.getSC(this.getDvMnfctrrModelName(), DataTypeUtil.getCE(this.getDvMnfctrrModelCodeEtsId(), "NullFlavor.NI"));
    }


    public void setSoftwareName(SC SoftwareName)
    {
        this.setDvSoftwareName(SoftwareName.toString());
        this.setDvSoftwareCodeEtsId(SoftwareName.code().toString());
    }


    public SC getSoftwareName() throws Hl7Exception
    {
        return DataTypeUtil.getSC(this.getDvSoftwareName(), DataTypeUtil.getCE(this.getDvSoftwareCodeEtsId(), "NullFlavor.NI"));
    }

    // Device
    @Column(name = "DV_MNFCTRR_MODEL_NAME")
    private String dvMnfctrrModelName;
    @Column(name = "DV_MNFCTRR_MODEL_CODE_ETS_ID")
    private String dvMnfctrrModelCodeEtsId;
    @Column(name = "DV_SOFTWARE_NAME")
    private String dvSoftwareName;
    @Column(name = "DV_SOFTWARE_CODE_ETS_ID")
    private String dvSoftwareCodeEtsId;
    @Column(name = "DV_LOC_REM_CTRL_STATE_ETS_ID")
    private String dvLocRemCtrlStateEtsId = LOCALREMOTECONTROLSTATECODE.toString();
    @Column(name = "DV_ALERT_LEVEL_CODE_ETS_ID")
    private String dvAlertLevelCodeEtsId = ALERTLEVELCODE.toString();
    @Column(name = "DV_LAST_CALIBRATION_DATE_TS")
    private Timestamp dvLastCalibrationDateTs;
    @Column(name = "DV_LAST_CALIBRATION_DATE_TXT")
    private String dvLastCalibrationDateTxt;


    private void setDvMnfctrrModelName(String dvMnfctrrModelName)
    {
        this.dvMnfctrrModelName = dvMnfctrrModelName;
    }


    private String getDvMnfctrrModelName()
    {
        return dvMnfctrrModelName;
    }


    private void setDvMnfctrrModelCodeEtsId(String dvMnfctrrModelCodeEtsId)
    {
        this.dvMnfctrrModelCodeEtsId = dvMnfctrrModelCodeEtsId;
    }


    private String getDvMnfctrrModelCodeEtsId()
    {
        return dvMnfctrrModelCodeEtsId;
    }


    private void setDvSoftwareName(String dvSoftwareName)
    {
        this.dvSoftwareName = dvSoftwareName;
    }


    private String getDvSoftwareName()
    {
        return dvSoftwareName;
    }


    private void setDvSoftwareCodeEtsId(String dvSoftwareCodeEtsId)
    {
        this.dvSoftwareCodeEtsId = dvSoftwareCodeEtsId;
    }


    private String getDvSoftwareCodeEtsId()
    {
        return dvSoftwareCodeEtsId;
    }


    private void setDvLocRemCtrlStateEtsId(String dvLocRemCtrlStateEtsId)
    {
        this.dvLocRemCtrlStateEtsId = dvLocRemCtrlStateEtsId;
    }


    private String getDvLocRemCtrlStateEtsId()
    {
        return dvLocRemCtrlStateEtsId;
    }


    private void setDvAlertLevelCodeEtsId(String dvAlertLevelCodeEtsId)
    {
        this.dvAlertLevelCodeEtsId = dvAlertLevelCodeEtsId;
    }


    private String getDvAlertLevelCodeEtsId()
    {
        return dvAlertLevelCodeEtsId;
    }


    private void setDvLastCalibrationDateTs(Timestamp dvLastCalibrationDateTs)
    {
        this.dvLastCalibrationDateTs = dvLastCalibrationDateTs;
    }


    private Timestamp getDvLastCalibrationDateTs()
    {
        return dvLastCalibrationDateTs;
    }


    private void setDvLastCalibrationDateTxt(String dvLastCalibrationDateTxt)
    {
        this.dvLastCalibrationDateTxt = dvLastCalibrationDateTxt;
    }


    @SuppressWarnings("unused")
    private String getDvLastCalibrationDateTxt()
    {
        return dvLastCalibrationDateTxt;
    }

}
